﻿@using EvertonApp.AdminWeb.Extensions
@model EvertonApp.AdminWeb.Models.PostModel

<script type="text/javascript">
    var jQuery = {};
</script>

<center>
<div id="divGridPosts">
    @if (@Model.Posts != null && @Model.Posts.Count() > 0)
    {
        WebGrid grid = new WebGrid(defaultSort: "FechaCreacion", rowsPerPage: 8, ajaxUpdateContainerId: "divGridPosts");
        grid.Bind(Model.Posts, autoSortAndPage: true, rowCount: Model.Posts.Count());
        @grid.GetHtml(
            fillEmptyRows: false,
            tableStyle: "table table-striped table-bordered table-condensed",
            mode: WebGridPagerModes.All,
            //firstText: "<< Primera",
            //previousText: "< Anterior",
            //nextText: "Siguiente >",
            //lastText: "Última >>",
            columns: new[]{
                //grid.Column("IdPost",header: "Nº Post", canSort: false),
                grid.Column("Titulo",header: "Titulo", canSort: false),
                grid.Column("FechaCreacion",header: "Fecha", canSort: false, format: @<text> @DateFormat.Convert(@item.FechaCreacion) </text> ),
                grid.Column("Tipo",header: "Tipo", canSort: false),
                grid.Column("NumeroComentarios",header: "Comentarios", canSort: false), 
                grid.Column("",header: "Acciones", format:@<text>
@*                                                               @Ajax.ActionLink("Ver", "Details", "Post2", new { id = item.IdPost }, new AjaxOptions{  HttpMethod = "GET", UpdateTargetId = "myModal", InsertionMode = InsertionMode.Replace, OnSuccess = "openPopup"} )*@
                                                                @Ajax.ActionLink("Eliminar", "Delete", "Post", new { IdHilo = item.IdHilo }, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "divGridPosts", OnComplete="limpiarCampos();" })
                                                            @if  (@item.Tipo == "Evento")
                                                            {
                                                               @Ajax.ActionLink("Editar", "EditEvento", "Post", new { IdHilo = item.IdHilo, Tipo = item.Tipo  }, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "myModal", InsertionMode = InsertionMode.Replace, OnSuccess = "openPopup();limpiarCampos();"})
                                                            }else
                                                            {
                                                               @Ajax.ActionLink("Editar", "Edit", "Post", new { IdHilo = item.IdHilo, Tipo = item.Tipo }, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "myModal", InsertionMode = InsertionMode.Replace, OnSuccess = "openPopup();limpiarCampos();"})
                                                            }       
                                                                @Ajax.ActionLink("Comentarios", "IndexComentario", "Post", new { idPost = item.IdHilo }, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "global"})

                                                           </text> )}
        )
    }
    else
    {
        <label>No se han encontrado comercios.</label>
    }
</div>
</center> 
